#!/bin/bash

export CUDA_VISIBLE_DEVICES=0
model_name=iTransformerCNN

# Common parameters
common_params="--task_name long_term_forecast \
  --is_training 1 \
  --root_path ./dataset/ETT-small/ \
  --data_path ETTh1.csv \
  --model $model_name \
  --data ETTh1 \
  --features M \
  --seq_len 96 \
  --label_len 48 \
  --e_layers 2 \
  --d_layers 1 \
  --factor 3 \
  --enc_in 7 \
  --dec_in 7 \
  --c_out 7 \
  --des 'iTransformerCNNExp' \
  --d_model 128 \
  --d_ff 128 \
  --itr 3"

# Run experiments for different prediction lengths
pred_lengths=(1 3 6 9 12 48 96 144 336 720)

for pred_len in "${pred_lengths[@]}"; do
  model_id="ETTh1_iTransformerCNN_96_${pred_len}"

  echo "Running experiment for prediction length: ${pred_len}"
  python -u run.py $common_params \
    --model_id $model_id \
    --pred_len $pred_len
done

# 运行不同数据集的实验
datasets=("ETTh2" "ETTm1" "ETTm2" "electricity" "weather")
pred_len_selected=(96 192 336 720)

for dataset in "${datasets[@]}"; do
  # 根据数据集调整参数
  if [[ "$dataset" == "ETTh2" ]]; then
    data_path="ETTh2.csv"
    enc_in=7
    dec_in=7
    c_out=7
  elif [[ "$dataset" == "ETTm1" ]]; then
    data_path="ETTm1.csv"
    enc_in=7
    dec_in=7
    c_out=7
  elif [[ "$dataset" == "ETTm2" ]]; then
    data_path="ETTm2.csv"
    enc_in=7
    dec_in=7
    c_out=7
  elif [[ "$dataset" == "electricity" ]]; then
    root_path="./dataset/electricity/"
    data_path="electricity.csv"
    enc_in=321
    dec_in=321
    c_out=321
  elif [[ "$dataset" == "weather" ]]; then
    root_path="./dataset/weather/"
    data_path="weather.csv"
    enc_in=21
    dec_in=21
    c_out=21
  fi

  # 为不同数据集更新参数
  dataset_params="--root_path ${root_path:-./dataset/ETT-small/} \
    --data_path $data_path \
    --data $dataset \
    --enc_in $enc_in \
    --dec_in $dec_in \
    --c_out $c_out"

  for pred_len in "${pred_len_selected[@]}"; do
    model_id="${dataset}_iTransformerCNN_96_${pred_len}"

    echo "Running experiment for dataset: ${dataset}, prediction length: ${pred_len}"
    python -u run.py $common_params $dataset_params \
      --model_id $model_id \
      --pred_len $pred_len
  done
done

# 消融实验 - 不同CNN卷积核大小
kernel_configs=("single" "dual" "triple" "quad")
kernel_args=("--cnn_kernel_sizes 3" "--cnn_kernel_sizes 3,5" "--cnn_kernel_sizes 3,5,7" "--cnn_kernel_sizes 3,5,7,11")

for i in {0..3}; do
  config=${kernel_configs[i]}
  args=${kernel_args[i]}

  model_id="ETTh1_iTransformerCNN_kernel_${config}"

  echo "Running ablation study for kernel configuration: ${config}"
  python -u run.py $common_params \
    --model_id $model_id \
    --pred_len 96 \
    $args
done

# 消融实验 - 融合模块变体
fusion_types=("gate" "concat" "attention")
fusion_args=("--fusion_type gate" "--fusion_type concat" "--fusion_type attention")

for i in {0..2}; do
  fusion=${fusion_types[i]}
  args=${fusion_args[i]}

  model_id="ETTh1_iTransformerCNN_fusion_${fusion}"

  echo "Running ablation study for fusion type: ${fusion}"
  python -u run.py $common_params \
    --model_id $model_id \
    --pred_len 96 \
    $args
done

# 复现性实验 - 使用不同随机种子
seeds=(42 43 44 45 46)

for seed in "${seeds[@]}"; do
  model_id="ETTh1_iTransformerCNN_seed_${seed}"

  echo "Running reproducibility test with seed: ${seed}"
  python -u run.py $common_params \
    --model_id $model_id \
    --pred_len 96 \
    --seed $seed
done

echo "All experiments completed!"

